package leetcode.tree;

import leetcode.tree.common.TreeNode;
import leetcode.tree.common.TreeUtils;

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 * int val;
 * TreeNode left;
 * TreeNode right;
 * TreeNode() {}
 * TreeNode(int val) { this.val = val; }
 * TreeNode(int val, TreeNode left, TreeNode right) {
 * this.val = val;
 * this.left = left;
 * this.right = right;
 * }
 * }
 */
class Solution993 {
    /**
     * 保证树中的每个节点的值均不同,值都是唯一的
     *
     * @param root
     * @param x
     * @param y
     * @return
     */
    public boolean isCousins(TreeNode root, int x, int y) {
        return TreeUtils.isCousins(root, x, y);
    }
}

public class leetcode993 {
    public static void main(String[] args) {
        Solution993 solution993 = new Solution993();
        Integer[] nums = {1, 2, 3, 4};
        Integer[] nums1 = {1, 2, 3, null, 4, null, 5};
        Integer[] nums2 = {1, 2, 3, null, 4};
        System.out.println(solution993.isCousins(TreeUtils.generateLeetcodeTree(nums), 4, 3));
        System.out.println(solution993.isCousins(TreeUtils.generateLeetcodeTree(nums1), 5, 4));
        System.out.println(solution993.isCousins(TreeUtils.generateLeetcodeTree(nums2), 2, 3));
    }
}
